import React from 'react';
import { Paper, Question } from '@/types/question';
import { Space, Tag, Divider, Card } from 'antd';
import { ClockCircleOutlined, TrophyOutlined, FileTextOutlined } from '@ant-design/icons';
import QuestionDisplay from './components/QuestionDisplay';
import styles from './PaperPreview.module.css';

interface PaperPreviewProps {
  paper: Partial<Paper>;
  questions: Question[];
}

const PaperPreview: React.FC<PaperPreviewProps> = ({ paper, questions }) => {
  const totalScore = questions.reduce((sum, q) => sum + ((q as any)._score || 10), 0);

  return (
    <div className={styles.preview}>
      {/* 试卷标题和信息 */}
      <div className={styles.header}>
        <h1>{paper.title || '未命名试卷'}</h1>
        {paper.description && (
          <p className={styles.description}>{paper.description}</p>
        )}

        <Space size="large" className={styles.info}>
          <Space>
            <FileTextOutlined />
            <span>题目数：{questions.length} 道</span>
          </Space>
          <Space>
            <TrophyOutlined />
            <span>总分：{totalScore} 分</span>
          </Space>
          <Space>
            <ClockCircleOutlined />
            <span>时长：{paper.duration || 0} 分钟</span>
          </Space>
          <Space>
            <Tag color="orange">及格分：{paper.passing_score || 60} 分</Tag>
          </Space>
        </Space>
      </div>

      <Divider />

      {/* 题目列表 */}
      <Space direction="vertical" size="large" style={{ width: '100%' }}>
        {questions.map((question, index) => (
          <Card
            key={index}
            title={`第 ${index + 1} 题（${((question as any)._score || 10)}分）`}
            className={styles.questionCard}
          >
            <QuestionDisplay 
              question={question} 
              index={index}
              onUpdateConfig={() => {}}
            />
          </Card>
        ))}
      </Space>

      {questions.length === 0 && (
        <div className={styles.empty}>
          暂无题目
        </div>
      )}
    </div>
  );
};

export default PaperPreview;

